//
//  LTY_MVPlayViewController.m
//  MooMusic
//
//  Created by 守护神 on 15/10/22.
//  Copyright © 2015年 wjy. All rights reserved.
//

#import "LTY_MVPlayViewController.h"
#import "KrVideoPlayerController.h"

@interface LTY_MVPlayViewController ()

@property (nonatomic, strong) KrVideoPlayerController  *videoController;

@end

@implementation LTY_MVPlayViewController

// 模态返回按钮触发的方法
- (void)goBackAction
{
    NSLog(@"模态返回消失");
    [self stop];
    [self dismissViewControllerAnimated:YES completion:^{
        
        
    }];
}


- (void)viewDidLoad {
    [super viewDidLoad];

    [self.navigationController.navigationBar setBarTintColor:COLOR(22, 88, 240, 1.0)];
    
    self.view.backgroundColor = [UIColor blackColor];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:self action:@selector(goBackAction)];
    
    [self playVideo];
    
    
    // Do any additional setup after loading the view.
}

- (void)stop
{
    self.videoController.judge = YES;
}

- (void)playVideo{
    // http://otmv.alicdn.com/new/mv_2_20/60/e7/6087dd4eb54b443830d45c868c84afe7.mp4?k=f02c840ea934bb1e&t=1445925369
    NSURL *url = [NSURL URLWithString:self.playString];
    [self addVideoPlayerWithURL:url];
}


- (void)addVideoPlayerWithURL:(NSURL *)url{
    if (!self.videoController) {
        CGFloat width = [UIScreen mainScreen].bounds.size.width;
        self.videoController = [[KrVideoPlayerController alloc] initWithFrame:CGRectMake(0, 240, width, width*(9.0/16.0))];
        //__weak typeof(self)weakSelf = self;
        [self.videoController setDimissCompleteBlock:^{
            self.videoController = nil;
        }];
        [self.videoController setWillBackOrientationPortrait:^{
            [self toolbarHidden:NO];
        }];
        [self.videoController setWillChangeToFullscreenMode:^{
            [self toolbarHidden:YES];
        }];
        [self.view addSubview:self.videoController.view];
    }
    self.videoController.contentURL = url;
    
}

- (void)toolbarHidden:(BOOL)Bool{
    self.navigationController.navigationBar.hidden = Bool;
    self.tabBarController.tabBar.hidden = Bool;
    [[UIApplication sharedApplication] setStatusBarHidden:Bool withAnimation:UIStatusBarAnimationFade];
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
